import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)

const routes = [{
  path: '*',
  redirect: '/'
}, {
  path: '/',
  name: 'index',
  component: () => import('@/view/index'),
  children: [{
    path: '',
    name: 'train',
    meta: {
      title: '课程中心'
    },
    component: () => import('@/view/train/main')
  }, {
    path: '/video',
    name: 'video',
    meta: {
      title: '视频课程'
    },
    component: () => import('@/view/train/video')
  }, {
    path: '/word',
    name: 'word',
    meta: {
      title: '图文课程'
    },
    component: () => import('@/view/train/word')
  }, {
    path: '/myTrain',
    name: 'myTrain',
    meta: {
      title: '我的课程'
    },
    component: () => import('@/view/train/myTrain')
  }, {
    path: '/exam',
    name: 'exam',
    meta: {
      title: '考试'
    },
    component: () => import('@/view/exam/main')
  }, {
    path: '/myPaper',
    name: 'myPaper',
    meta: {
      title: '我的考试'
    },
    component: () => import('@/view/exam/myPaper')
  }, {
    path: '/paper',
    name: 'paper',
    meta: {
      title: '试题'
    },
    component: () => import('@/view/exam/paper')
  }, {
    path: '/paperResult',
    name: 'paperResult',
    meta: {
      title: '考试结果'
    },
    component: () => import('@/view/exam/paperResult')
  }, {
    path: '/mine',
    name: 'mine',
    meta: {
      title: '个人中心'
    },
    component: () => import('@/view/mine/main')
  }, {
    path: '/userInfo',
    name: 'userInfo',
    meta: {
      title: '个人信息'
    },
    component: () => import('@/view/mine/userInfo')
  }]
}]

const Router = new VueRouter({
  mode: 'history',
  // base: '/h5/',
  routes
})

Router.afterEach(to => {
  let title = ''
  if (to.meta && to.meta.title) {
    title = to.meta.title
  } else {
    title = to.query.name
  }
  document.title = title
})

export default Router
